package cn.aishua.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RadioButton;

public class ViewHelper
{

    public static String extractText( Activity context, int resId )
    {
        String text = null;
        View view = context.findViewById( resId );
        if( view instanceof EditText )
        {
            EditText editText = (EditText) view;
            text = editText.getText().toString().trim();
        }
        else if( view instanceof RadioButton )
        {
            RadioButton radioButton = (RadioButton) view;
            text = radioButton.getText().toString().trim();
        }
        return text;
    }

    public static void hideKeyboard( Activity context )
    {
        InputMethodManager imm = (InputMethodManager) context.getSystemService( Context.INPUT_METHOD_SERVICE );
        if( context.getCurrentFocus() != null )
            imm.hideSoftInputFromWindow( context.getCurrentFocus().getWindowToken(), 0 );
    }

}
